package com.yangchuang.openpicture.util;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class ImageDimensionUtils {

    public static int[] getDimensions(byte[] imageBytes) throws IOException {
        try (ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes)) {
            BufferedImage image = ImageIO.read(inputStream);
            if (image == null) {
                throw new IOException("无法解析图片尺寸，可能格式不支持");
            }
            return new int[]{image.getWidth(), image.getHeight()};
        }
    }
}
